package com.konsung.ksdc.common.widget;

import android.view.View;
import android.widget.AdapterView;

/**
 * 重写listView item点击事件，防止多次响应
 * Created by DJH on 2017/4/5 0005.
 */
public abstract class OnItemMultiClickListener implements AdapterView.OnItemClickListener {

    private static final int MIN_CLICK_DELAY_TIME = 1000; // 两次点击按钮之间的点击间隔不能少于1000毫秒

    private static long lastClickTime; // 记录上次点击时间戳

    /**
     * 构造方法
     * @param parent 父控件
     * @param view view
     * @param position 位置
     * @param id id
     */
    public abstract void onItemMultiClick(AdapterView<?> parent, View view, int position, long id);

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        long curClickTime = System.currentTimeMillis();
        if ((curClickTime - lastClickTime) >= MIN_CLICK_DELAY_TIME) {
            // 超过点击间隔后再将lastClickTime重置为当前点击时间
            lastClickTime = curClickTime;
            onItemMultiClick(parent, view, position, id);
        }
    }
}
